# @File    : test.py
# @Project : Airtest_test
__author__ = "TJYF18"

from airtest.core.api import *
from poco.drivers.android.uiautomation import AndroidUiautomationPoco
from common.connect import connect
from common.operate import OperateUtil
from common.yamlUtil import YamlUtil
import logging
logger = logging.getLogger("airtest")
logger.setLevel(logging.ERROR)
conf = YamlUtil("location.yaml").read_yaml()
process = "^.*%"

connect()
# 初始化 Poco
poco = AndroidUiautomationPoco()
operate = OperateUtil(poco)
print("start...")
print(poco("jbl.stc.com.debug:id/tvProgress").get_text())
print(type(poco("jbl.stc.com.debug:id/tvProgress").get_text()))
print(poco(textMatches=f"{process}").get_text())
# # 启动app
# start_app("jbl.stc.com.debug")
#
# sleep(2)
# if poco(text="Others").exists():
#     keyevent("BACK")
# poco(f"{conf['exclamation']}").click()
# # operate.element_click(f"{conf['exclamation']}", 5)
# sleep(1)
# touch(v=(540, 2331), times=15)
# sleep(2)
# # d = poco("jbl.stc.com.debug:id/btExplore")
# # d.click()
# if poco("jbl.stc.com.debug:id/btExplore").exists():
#     keyevent("BACK")
# checkbox = poco("jbl.stc.com.debug:id/checkBoxFOta")
# if checkbox.attr("checked") == "true":
#     poco("jbl.stc.com.debug:id/buttonSelect").click()
# else:
#     checkbox.click()
#     poco("jbl.stc.com.debug:id/buttonSelect").click()
# sleep(1)
# poco("显示根目录").click()
# touch(v=(286, 1086))
# poco(text="01_LIVEFLEX3_FW_OTA_V0.6.8").click()
# poco(text="LIVEFLEX3_Headset_OTA_v0.6.8.bin").click()
# poco("jbl.stc.com.debug:id/image_view_back").click()
# poco("jbl.stc.com.debug:id/image_view_info_back").click()
# poco("android.widget.FrameLayout").offspring("jbl.stc.com.debug:id/grid_view_dashboard").child("android.widget.LinearLayout")[0].offspring("jbl.stc.com.debug:id/image_view_item_connected_before_device_icon").click()
# poco(text="Others").click()
# poco(text="支持").click()
# poco(text="软件").click()
# # d = operate.location(5, name="jbl.stc.com.debug:id/btExplore", text="导出")
# # d.click()
# # print(d)
# print("end...")
# stop_app("jbl.stc.com.debug")
# PocoNoSuchNodeException


# # 耳机按键
# poco("android.widget.FrameLayout").offspring("jbl.stc.com.debug:id/grid_view_dashboard").child("android.widget.LinearLayout")[0].offspring("jbl.stc.com.debug:id/image_view_item_connected_before_device_icon")
# poco("android.widget.FrameLayout").offspring("jbl.stc.com.debug:id/grid_view_dashboard").child("android.widget.LinearLayout")[0].offspring("jbl.stc.com.debug:id/image_view_item_connected_before_device_icon")
# daochu = poco(text="导出").wait(10) #导出按键
# print(daochu)
#
# print(poco("jbl.stc.com.debug:id/btExplore",text="导出").wait_for_appearance(5))
# poco("jbl.stc.com.debug:id/checkBoxFOta") #复选框
# poco("jbl.stc.com.debug:id/buttonSelect") #SELECT 按键
# poco("显示根目录").click()
# poco(text="下载内容").click()
# poco(text="01_LIVEFLEX3_FW_OTA_V0.7.4") #选择安装包
# poco(text="LIVEFLEX3_CC_OTA_V2.4.0.bin")
# poco(text="LIVEFLEX3_Headset_OTA_v0.7.0.bin")
# poco("jbl.stc.com.debug:id/image_view_back") #选择安装包后的返回按键
# poco("jbl.stc.com.debug:id/image_view_info_back")
# poco("android.widget.FrameLayout").offspring("jbl.stc.com.debug:id/grid_view_dashboard").child("android.widget.LinearLayout")[0].offspring("jbl.stc.com.debug:id/image_view_item_connected_before_device_icon")
# poco(text="Others")
# poco(text="支持")
# poco(text="软件")
# poco(text="智能保护盒")
# poco(text="耳机：  v0.6.8")
# poco(text="充电盒：  v2.2.0")
# poco(text="更新")
# poco("jbl.stc.com.debug:id/tvProgressState") #剩余下载时间
# poco("jbl.stc.com.debug:id/tvLlFirmwareUpdatingStatus") #正在安装
# poco(text="取消")
# poco(text="退出")
# poco(text="更新成功")
# poco(text="完成")
# keyevent("BACK")
# poco(text="取消")
# poco(text="更新失败")
# poco("jbl.stc.com.debug:id/tvLlFirmwareUpdatingMsg")
# poco(text="抱歉，更新耳机时遇到问题。未进行任何更改。")
# poco("蓝牙开启。")
poco("蓝牙开启。") # 未回连
poco("蓝牙已连接。") # 已回连
poco("已连接到蓝牙。") # 状态栏已连接耳机
poco("蓝牙,开启,未连接。") # 状态栏伪关闭蓝牙
swipe((840, 30), (840, 330)) # 下滑状态栏
sleep(2)
swipe((840, 2200), (840, 1330)) # 上拉状态栏
# # assert_equal(daochu, "导出", "导出存在，点击返回")
# # poco("android.widget.FrameLayout").offspring("android:id/content").offspring("android.widget.ScrollView").offspring("jbl.stc.com.debug:id/image_view_back").click() #返回按键